/*
ID: guoxu1
PROG: palsquare
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;

const char digits[] = { '0','1','2','3','4','5','6','7','8','9',
	'A','B','C','D','E','F','G','H','I','J' };

const int ML = 18;

#define cin fin
#define cout fout

void getstringofbase( int num, int base, char str[ML] )
{
	char* p = str;
	while( num > 0 )
	{
		(*p++) = digits[ num % base ];
		num /= base;
	}
}

void print( ostream& cout, char str[ML] )
{
	int h = ML - 1;
	while( str[h] == '\0' ) h--;
	while( h >= 0 )
	{
		cout << str[h--];
	}
}

bool palindrome( char str[ML] )
{
	int h = ML - 1;
	while( str[h] == '\0' ) h--;
	int l = 0;
	while( str[l] == str[h] )
	{
		l++; h--;
	}
	return ( l >= h );
}

int main()
{
	ifstream fin( "palsquare.in" );
	ofstream fout( "palsquare.out" );

	int base = 0;
	cin >> base;

	for( int i = 1; i <= 300; i++ )
	{
		char square[ML] = {0};
		getstringofbase( i * i, base, square );
		if( palindrome( square ) )
		{
			char original[ML] = {0};
			getstringofbase( i, base, original );

			print( cout, original );
			cout << " ";
			print( cout, square );
			cout << endl;
		}
	}

	return 0;
}
